(function (G) {
    G.vue({
        data: {
            list: [],
            /**
             * 负责人 userId
             * 预设发送信息 preInfo
             * 预案名称 preName
             * 关联预案id f_flowId
             * 事件描述 description
             * 剩余处理时间 surplusTime
             * 状态 status
             * 流程id taskID
             * 当前处理人 toUsers
             */
            userId: null,
            preInfo: null,
            preName: null,
            f_flowId: null,
            description: null,
            surplusTime: null,
            status: null,
            taskID: null,
            toUsers: null,
        },
        methods: {
            getAllEmerg() {
                let that = this
                G.get('/api/model/f_flow', {
                    type: 'yjya'
                }).then(res => {
                    if (!res.errorMsg) {
                        console.log('---res', res);
                        that.setData({
                            list: res
                        })
                    }
                })
            },
            commit(event) {
                let item = this.data.list[event.currentTarget.dataset.index]
                G.get('/api/model/f_node',{id:item.f_nodeId}).then(res => {
                    if(res.form){
                        let form = JSON.parse(res.form)
                        var modeleditquery = {
                            values: {},
                            title: item.name,
                            meth: 'POST',
                            models: form,
                            // url: '/api/model/g_emergency_plan',
                            submit:data=>{
                                data.userId = G.Storage.get('userInfo').userId
                                data.userName = G.Storage.get('userInfo').name
                                data.file = item.file
                                data.massage = item.expand1
                                form.userName = {
                                    label:'发起人',
                                    type:'input'
                                }
                                form.file = {
                                    label:'预案内容',
                                    type:'file'
                                }
                                G.post('/v1/task/add', {
                                    userId: data.userId,
                                    flowId: item.id,
                                    data,
                                    form,
                                    title: data.description || item.name,
                                }).then(res => {
                                    if(!res.errorMsg){
                                        G.toask('发起成功').then(res => {
                                            G.$back()
                                        })
                                    }
                                })
                            }
                        }
                        modeleditquery.values.userId = G.Storage.get('userInfo').userId
                        modeleditquery.models.userName = null
                        G.Storage.set('modeleditquery', modeleditquery)
                        G.$go('/pages/model/edit/edit')
                    }else{
                        G.toask('此预案尚未配置出来流程，请联系管理员')
                    }
                })
            },
            // 格式化时间
            formatDate1(times) {
                var date = new Date(times);
                var year = date.getFullYear().toString(); //年份
                var month = (date.getMonth() + 1).toString(); //月份
                var day1 = date.getDate(); //日
                if (day1.toString().length == 1) {
                    var day = '0' + day1.toString()
                } else {
                    var day = day1.toString()
                }
                var hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
                var minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
                var second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
            },
        },
        mounted() {
            // this.getAllFlow()
            // this.getAllUser()
            this.getAllEmerg()
        }
    })
})(wx.$)